package com.group2.view;
import static model.netBase.IP;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Random;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import javax.swing.text.html.ImageView;

import java.awt.*;

import java.util.Vector;
import model.*;
public class buttonadd implements TableCellRenderer {
  private JPanel jPanel;
  private JButton jButton;
  public String name;

  public buttonadd(String name) {
	this.name=name;
    initJPanel();
    initButton();
    jPanel.add(jButton);
    jButton.setEnabled(true);
  }

  private void initButton() {
	  Font f = new Font("黑体", Font.PLAIN, 12);
      jButton = new JButton();
      jButton.setBounds(7, 3, 60, 20);
      jButton.setFont(f);
      jButton.setEnabled(true);
      jButton.addMouseListener(new MouseAdapter(){            
    	 	@Override            
    	 	public void mouseClicked(MouseEvent e){                
    	 		if(e.getButton() == MouseEvent.BUTTON1) System.out.println("左键");                
    	 		else if(e.getButton() == MouseEvent.BUTTON2) System.out.println("中键");                
    	 		else if(e.getButton() == MouseEvent.BUTTON3) System.out.println("右键");
    	 	
    			int cc = e.getClickCount();                
    			if(cc == 1) System.out.println("单机");                
    			else if(cc == 2) System.out.println("双击");
    		
    			System.out.println("鼠标位置:" + e.getX() +  "," + e.getY());                
    			System.out.println("------------");            
    		}        
    	});
      jButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
        	 JOptionPane.showMessageDialog(null, name+"成功");
            System.out.println("" + e.getActionCommand());
            System.out.println(jButton.getText());
          }
        });
  }

  private void initJPanel() {
      jPanel = new JPanel();
      jPanel.setLayout(null);
  }

  @Override
  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
	  jButton.setEnabled(true);
      jButton.setText(name);
    return jPanel;
  }
}


